<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Collectiondetails_model extends CI_Model {
	public function __construct() {
		parent::__construct();
	}

	public function get_status($range1, $range2,$date1, $date2,$ref1 ,$ref2) {
		// $this->db->where('receipt_number BETWEEN "' . $range1 . '" AND "' . $range2 . '" ');
		// $query = $this->db->get('collection_details');
		// return $query->result();
		$query = $this->db->query("SELECT * FROM ubs_collection_details_v
								   WHERE (receipt_number BETWEEN IFNULL('$range1','$range1') AND IFNULL('$range2','$range2'))
								      OR (receipt_date BETWEEN IFNULL(CAST('$date1' AS DATE),CAST('$date2' AS DATE)) AND IFNULL(CAST('$date2' AS DATE),CAST('$date1' AS DATE)))
								      OR (reference BETWEEN IFNULL('$ref1','$ref2') AND IFNULL('$ref2','$ref1'))");
		return $query->result();
	}

	public function get_email($type) {
		$this->db->where('mail_interval_type', $type);
		$this->db->where('enable_flag', 'Y');
		$query = $this->db->get('email');
		return $query->result();
	}
	public function update_sentemail($id) {
		$this->db->where('email_id', $id);
		$this->db->update('email', array('is_sent' => 1));
	}
}